<% extends 'stock/weui_base.html' %>
<% block title %>出货单<% endblock %>
<% block body %>
<style>
    .weui_input{text-align: right}

    .weui-input-right{
    border-left: 1px solid #e5e5e5;
    color: #aaa;
    display: inline-block;
    font-size: 17px;
    height: 44px;
    line-height: 44px;
    margin-left: 5px;
    padding: 0 .6em 0 .7em;
    vertical-align: middle;
    }
    .no-reserved{
        color:red;
    }
</style>
<script>
    var picking_id = ${picking_id};
    var picking_user_name = '${picking_user_name|safe}';
    var from = '${from}';
    var picture_list_rows =  [ <% for picture in picking_row.picture_list_ids %> '${picture.image_sign}', <% endfor %> ];
    var state ='${state}';
    var tracking_number ='${tracking_number|safe}';
    var note = '${note|safe}';
    var shipping_type_sale = '${shipping_type_sale|safe}';
    if(note=='False'){
        note = ''
    }
    var packages_number = '${packages_number|safe}';
    var total_weight_kilo = '${total_weight_kilo|safe}';
    var is_show_note_shipping_type = '${is_show_note_shipping_type|safe}';
    if(is_show_note_shipping_type=='False') {
        is_show_note_shipping_type = false;
    }else{
        is_show_note_shipping_type = true;
    }
    var user_list = ${user_list|to_json|safe};
    var user_id = ${user_id};
    var has_service_manager = ${has_service_manager|to_json};
    var delivery_user_id = ${delivery_user_id} + 0;
    var is_sign = ${is_sign|to_json};
    var move_lines = {
        <% for move_line in picking_row.move_lines %>
            ${move_line.id}: {
                product_qty: ${move_line.product_qty|int},
                reserved_availability: ${move_line.reserved_availability|int}
        },
        <% endfor %>
    };



//    function update_and_print_picking() {
//        //检查送货人是否有值
//        var values = $('#delivery-person-select').data('values');
//        var delivery_person_name = $('#delivery-person-select').val();
//        if (!delivery_person_name) {
//            $.toptips('请选择送货人');
//            return;
//        }
//        else {
//            $('#td_delivery_name').text(delivery_person_name);
//            $('#span_delivery_name').text(delivery_person_name);
//            var data = {delivery_user_id: values};
//            window.update_delivery_user_id(data).then(function (data) {
//                $.hideLoading();
//                print_picking();
//            }, function () {
//                $("#delivery-person-select").val('');
//                $.toast("送货人更新失败", "forbidden");
//            });
//        }
//    }


</script>

<h3 style="text-align: center"><% if picking_row.picking_type_id.id==1 %>入库单<% endif %>
            <% if picking_row.picking_type_id.id==2 %>出库单<% endif %> 领货</h3>
<div class="weui-form-preview">
<form id="form-picking">

    <input id="picking_id" name="picking_id" type="hidden" value="${picking_id}" />
    <p class="page-hd-desc">销售员:${sale_order.user_id.name} 客户:${sale_order.partner_id.name}</p>
    <p v-if="has_service_manager || (user_id==delivery_user_id && !is_sign)" class="page-hd-desc">联系人:${picking_row.consignee} 手机:<a href="tel:${picking_row.mobile_number}">${picking_row.mobile_number}</a>
    电话:<a href="tel:${sale_order.phone_number}">${picking_row.phone_number}</a>
        <p>
        地址：<span>
                    <% if picking_row.province_id and picking_row.province_id.name != '上海市' %>
                    ${sale_order.province_id.name}
                    <% endif %>
                    <% if picking_row.city_id %>
                    ${sale_order.city_id.city_name}
                    <% endif %>
                    <% if picking_row.county_id %>
                    ${sale_order.county_id.county_name}
                    <% endif %>
                    ${ sale_order.street|default('', True) }</span>
        </p>
    </p>
    <div class="weui-form-preview-hd">
        <label class="weui-form-preview-label">
            ${sale_order.name}
            </label>
        <em class="weui-form-preview-value">${picking_row.name}</em>
    </div>

    <table width="100%" border="0" cellSpacing="0" cellPadding="0" bordercolor="#000000" style="border-collapse:collapse;font-size:12px">
        <thead style="font-weight: bold">
            <tr>
                <td style="border-bottom: 1px solid #aaa" width="15">#</td>
                <td style="border-bottom: 1px solid #aaa">产品名称</td>
                <td style="border-bottom: 1px solid #aaa">备注</td>
                <td nowrap="nowrap" style="border-bottom: 1px solid #aaa" align="right">数量</td>
            </tr>
        </thead>
        <tbody>
            <% for move_line in picking_row.move_lines %>
            <tr v-bind:class="{'no-reserved': !lines_stock_reserved[${move_line.id}]}">
                <td style="border-bottom: 1px solid #aaa">${loop.index}</td>
                <td style="border-bottom: 1px solid #aaa">
                        <span>${move_line.name}</span>
                </td>

                <td style="border-bottom: 1px solid #aaa">${move_line.prod_spec|default("", True)}</td>
                <td style="border-bottom: 1px solid #aaa" align="right">
                    {{ move_lines[${move_line.id}].product_qty }}({{ move_lines[${move_line.id}].reserved_availability }})</td>
            </tr>
				<% for order_card in sale_order.sale_order_id %>
						<% if order_card.product_id.id==move_line.product_id.id %>
						<tr>
							<td></td>
							<td style="text-align: left;" colspan="7">
							券号:${order_card.starting_number.code}<% if order_card.continue_number!=1 %>~${order_card.ending_number}(${order_card.continue_number}张)<% else %> (${order_card.continue_number}张)<% endif %>
							</td>
						</tr>
						<% endif %>
				<% endfor %>
            <% endfor %>

            <% if official_invoice_map.get(False) or official_invoice_map.get(True) %>
            <tr><td colspan="8">
                <% if official_invoice_map.get(False) %>已开票:${official_invoice_map.get(False)}张<% endif %>
                <% if official_invoice_map.get(True) %>发票:${official_invoice_map.get(True)}张(W)<% endif %>
            </td></tr>

            <% endif %>
        </tbody>
        <tfoot>
          <tr>
            <td width="100%" colspan="4" style="font-size:12px">
                ${sale_order.note|default(' ',True)|replace('\n', '<br/>')|safe}
            </td>
          </tr>
        </tfoot>
    </table>
    <div class="weui-form-preview-hd">
        <label class="weui-form-preview-label">
            拣货人:
            </label>
        <em class="weui-form-preview-value"><div v-if="picking_user_name">{{picking_user_name}}</div><div v-else>未拣货</div></em>
    </div>
    <div class="weui-form-preview-hd">
        <label class="weui-form-preview-label">
            领货(送货)人:
            </label>
        <em class="weui-form-preview-value"><% if picking_row.delivery_user_id %>${picking_row.delivery_user_id.name}<%else%>${user_name}<% endif %></em>
    </div>
    <template v-if="delivery_user_id == '' && !is_sign && state != 'done'">
        <div class="weui_cells" v-if="is_show_note_shipping_type">
            <div class="weui_cell weui_cell_select weui_select_after">
                <div class="weui_cell_hd">
                    <label for="select2" class="weui_label">送货方式</label>
                </div>
                <div class="weui_cell_bd weui_cell_primary">
                    <select class="weui_select" name="select2" v-model="shipping_type_sale">
                        <option value="False"></option>
                        <option value="express_delivery">快递</option>
                        <option value="sale_delivery">销售送货</option>
                        <option value="self_logistics">公司物流</option>
                        <option value="direct_delivery">供应商直送</option>
                        <option value="take_car">打车</option>
                    </select>
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">份数</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="number" pattern="[0-9]*" placeholder="请输入份数" v-model="packages_number">
                </div>
            </div>
             <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">总重量(公斤)</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="number" pattern="[0-9]*" placeholder="请输入总重量（公斤）" v-model="total_weight_kilo">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_bd weui_cell_primary">
                    <textarea id="textarea" class="weui_textarea" placeholder="仓库备注" rows="3" v-model="note"></textarea>
                </div>
            </div>
        </div>
    </template>
    <a v-if="delivery_user_id == '' && !is_sign && state != 'done' && picking_user_name == ''" id="picking-pickup_picking" href="javascript:;" class="weui_btn bg-blue" v-on:click="picking_goods">确认拣货</a>

    <a v-if="delivery_user_id == '' && !is_sign && state != 'done'" id="picking-pickup_begin_delivery"
       href="javascript:;" class="weui_btn bg-blue" v-on:click="picking_take_up">确认领货出库</a>
    <a v-if="delivery_user_id == '' && !is_sign && state == 'done'" id="picking-pickup_confirm" href="javascript:;"
       class="weui_btn bg-blue" v-on:click="picking_take_up">确认领货（已出库）</a>
    <a v-show="(user_id==delivery_user_id) && !is_sign" id="picking-sign" href="javascript:;"
       class="weui_btn bg-blue" v-on:click="picking_sign">确认送达并签收</a>
    <div class="weui-form-preview-hd"  v-show="user_id!=delivery_user_id && delivery_user_id != '' ">
        <label class="weui-form-preview-label">
            送货状态:
            </label>
        <em class="weui-form-preview-value"><div v-if="is_sign">送货完成</div><div v-else>已出库未送达</div></em>
    </div>

     <div v-show="shipping_type_sale=='express_delivery'">
        <div class="weui_cells_title">快递单号</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_bd weui_cell_primary">
                    <textarea id="textarea_tracking_number" class="weui_textarea"
                              placeholder="快递单号（多个快递单号请换行输入）" rows="3" v-model="tracking_number"></textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="weui_btn_area weui_btn_area_inline" v-show="shipping_type_sale=='express_delivery'">
        <a href="javascript:;" class="weui_btn weui_btn_primary" v-on:click="scan_qrcode">扫码快递单号</a>
        <a  id="change-tracking-umber" href="javascript:;" class="weui_btn weui_btn_primary" v-on:click="change_tracking_number">保存快递单号</a>
    </div>
    <!--<a href="javascript:;" class="weui_btn bg-blue">批量领货</a>-->
    <div v-show="is_sign">
        <div class="weui_msg">
            <i class="weui_icon_success weui_icon_msg"></i>
            <div class="icon-box__ctn">
                <h3 class="icon-box__title">送货已完成</h3>
                <% if delivery_done_time %>
                <div class="weui_msg_desc"><span slot="content">签收时间：${delivery_done_time|strftime('%Y-%m-%d %H:%M')|default('',True)}</span></div>
                <% endif %>
            </div>
        </div>
        <a id="take_a_picture" href="javascript:;" class="weui_btn bg-blue" v-on:click="take_a_picture">拍照留存</a>
        <div>
            <i class="icon-box__title">上传图片列表</i>
            <template v-for="picture in sign_pictures">
                <img :src="picture" style="width: 100%">
            </template>
        </div>
    </div>
</form>
</div>
<script src="/dftg_weixin/static/src/js/stock/stock_app.js?v1.070"></script>
<% endblock %>
